//
// Created by 86131 on 2023/11/10.
//
#include <iostream>
#include <queue>
using namespace std;
const int N = 1010;
int in_order[N], post_order[N];
int n;

struct node
{
    int data;
    node *lchild;
    node *rchild;
};

node *build(int inL, int inR, int postL, int postR)
{
    if (inL > inR)
        return NULL;
    node *root;
    root = new node;
    root->data = post_order[postR];
    int k = inL;
    while (in_order[k] != root->data)
        k++;
    int numLeft = k - inL;
    root->lchild = build(inL, k - 1, postL, postL + numLeft - 1);
    root->rchild = build(k + 1, inR, postL + numLeft, postR - 1);
    return root;
}

void bfs(node *root)
{
    int num = 0;
    queue<node *> q;
    q.push(root);
    while (q.size())
    {
        node *now = q.front();
        q.pop();
        cout << now->data;
        num++;
        if (num < n)
            cout << " ";
        if (now->lchild != NULL)
            q.push(now->lchild);
        if (now->rchild != NULL)
            q.push(now->rchild);
    }
}

int main()
{
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> in_order[i];
    for (int i = 0; i < n; i++)
        cin >> post_order[i];

    node *root = build(0, n - 1, 0, n - 1);
    bfs(root);
    return 0;
}